package org.neowei.image.filter;

import java.awt.image.BufferedImage;

public class VerticalFilter implements Runnable {
	private final BufferedImage outimage;
	private final BufferedImage srcimage;
	private final int startY;
	private final int stopY;
	private final int start;
	private final int y;
	private final double[] normalContrib;
	private final int neowidth;

	public VerticalFilter(BufferedImage outimage, BufferedImage srcimage, int startY, int stopY, int start, int y, double[] normalContrib, int neowidth) {
		this.outimage = outimage;
		this.srcimage = srcimage;
		this.startY = startY;
		this.stopY = stopY;
		this.start = start;
		this.y = y;
		this.normalContrib = normalContrib;
		this.neowidth = neowidth;
	}

	@Override
	public void run() {
		for (int x = 0; x <= neowidth; x++) {
			double valueRed = 0, valueGreen = 0, valueBlue = 0;
			for (int i = startY, j = start; i <= stopY; j++, i++) {
				int valueRGB = srcimage.getRGB(x, i);
				double contributor = normalContrib[j];
				valueRed = Filter.getRedValue(valueRGB, valueRed, contributor);
				valueGreen = Filter.getGreenValue(valueRGB, valueGreen, contributor);
				valueBlue = Filter.getBlueValue(valueRGB, valueBlue, contributor);
			}
			outimage.setRGB(x, y, Filter.comRGB(Filter.clip((int) valueRed), Filter.clip((int) valueGreen), Filter.clip((int) valueBlue)));
		}
	}
}
